#include <bits/stdc++.h>

using namespace std;
using ll = long long;

typedef pair<int, int> pii;

const int MAXN = 2e5 + 10;
const int MOD = 1e9 + 7;

int t, n;
ll k, a[MAXN], sum[MAXN];

int main() {
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    ios::sync_with_stdio(false), cin.tie(0);

    cin >> t;
    while (t--) {
        cin >> n >> k;
        for (int i = 1; i <= n; i++) cin >> a[i];
        sort(a + 1, a + 1 + n);
        for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + a[i];
        ll ans = 1e16;
        for (ll i = n; i >= 1; i--) {
            if (sum[i] + (n - i) * a[1] <= k) {
                ans = min(ans, n - i);
                continue;
            }
            int b = floor((k + a[1] - sum[i]) * 1.0 / (n - i + 1));
            if (b < a[1]) {
                ans = min(ans, a[1] - b + n - i);
            }

        }
        cout << ans << endl;
    }
    return 0;
}